/**
 * Created by Neo on 2017/3/14.
 */

var scope={
    save_url:'',
    status_url:'',
    remove_url:''
};

$(function(){

    $('#ssly-form').validationEngine();

    $('.skin-minimal input').iCheck({
        checkboxClass: 'icheckbox-blue',
        radioClass: 'iradio-blue',
        increaseArea: '20%'
    });

    var flag=true;

    $('#ssly-form').submit(function () {
        if ($(this).validationEngine('validate')){
            if (!flag){
                return false;
            }
            flag=false;
            $.post(scope.save_url,$(this).serialize(),function (result) {
                if(result.status==1){
                    layer.alert(result.info,{icon:6},function () {
                        parent.location.reload();
                    })
                }else {
                    layer.alert(result.info,{icon:5})
                }
                flag=true;
            },"json");
        }
        return false;
    });
});
//改变状态
function status(id, action) {
    $.ajax({
        type: 'GET',
        url: scope.status_url,
        data: {id:id,action:action},
        dataType: 'json',
        success: function (result) {
            if (result.status == 1) {
                layer.alert(result.info, {icon: 6}, function () {
                    location.reload();
                });
            } else {
                layer.alert(result.info, {icon: 5});
            }
        }

    })
}
//彻底删除
function remove(id) {
    $.ajax({
        type: 'GET',
        url: scope.remove_url,
        data: {id:id,status:status},
        dataType: 'json',
        success: function (result) {
            if (result.status == 1) {
                layer.alert(result.info, {icon: 6}, function () {
                    location.reload();
                });
            } else {
                layer.alert(result.info, {icon: 5});
            }
        }

    })
}
